<include file="public:header" />
       <div class="toptip">
        <div class="toptit">提示：</div>
        <p>您可以通过发送测试邮件来调试配置信息。</p>
        <p>通过连接 SMTP 服务器发送邮件需邮箱账户开通SMTP服务。</p>
        <p>您可以添加多个SMTP账户，系统将随机使用SMTP账户。</p>
        <p class="link_green_line">如需使用阿里云邮件推送服务，请先登录阿里云官方网站申请api权限。<a href="https://help.aliyun.com/product/29412.html" target="_blank">立即申请</a>。</p>
        <p class="link_green_line">阿里云邮件推送控制台地址：<a href="https://dm.console.aliyun.com" target="_blank">https://dm.console.aliyun.com</a></p>
      </div>
<div class="toptit">设置</div>
<form action="{:U('mailconfig/index')}" method="post"   name="form1" id="form1">
    <div class="form_main width150">
        <div class="fl">接口类型：</div>
        <div class="fr">
          <div class="imgradio">
              <input name="api_type" class="api_type" type="hidden" value="<if condition="in_array($info['method'],array('1','2','3'))">normal<else/>aliyun</if>">
              <div class="J_api_type radio <if condition="in_array($info['method'],array('1','2','3'))">select</if>" data="normal" title="系统API">系统API</div>
              <div class="J_api_type radio <if condition="$info['method'] eq 4">select</if>" data="aliyun" title="阿里云DirectMail API">阿里云DirectMail API</div>
              <div class="clear"></div>
          </div>
        </div>
        <div class="clear"></div>
    </div>
    <div id="normal-block">
        <div id="methodsel" class="form_main width150">
            <div class="fl">发送方式：</div>
            <div class="fr">
              <div class="imgradio">
                  <input name="method" type="hidden" value="">
                  <div class="radio <if condition="$info['method'] eq 1">select</if>" data="1" title="通过连接 SMTP 服务器发送邮件">通过连接 SMTP 服务器发送邮件</div>
                  <div class="radio <if condition="$info['method'] eq 2">select</if>" data="2" title="通过sendmail 发送邮件">通过sendmail 发送邮件</div>
                  <div class="radio <if condition="$info['method'] eq 3">select</if>" data="3" title="通过 PHP 函数 SMTP 发送邮件">通过 PHP 函数 SMTP 发送邮件</div>
                  <div class="clear"></div>
              </div>
            </div>
            <div class="clear"></div>
        </div>
        <div style="display:none;"  id="method_sendmail">
            <volist name="list" id="list">
                <div class="html_tpl form_main width150">
                    <div class="fl">SMTP服务器地址：</div>
                    <div class="fr">
                        <input name="smtpservers[]" id="smtpservers" type="text" maxlength="30" class="input_text_default middle" value="{$list.smtpservers}"/>
                        <label class="no-fl-note">如：smtp.qq.com</label>
                        <span style="color:#0066CC; cursor:pointer" class="delsmtp">X 删除此账户</span>
                    </div>
                    <div class="fl">SMTP服务帐户名：</div>
                    <div class="fr">
                        <input name="smtpusername[]" id="smtpusername" type="text" maxlength="100" class="input_text_default middle" value="{$list.smtpusername}"/>
                    </div>
                    <div class="fl">SMTP服务密码：</div>
                    <div class="fr">
                        <input name="smtppassword[]" id="smtppassword" type="password" maxlength="40" class="input_text_default middle" value="{$list.smtppassword}"/>
                    </div>
                    <div class="fl">发信人邮件地址：</div>
                    <div class="fr">
                        <input name="smtpfrom[]" id="site_title" type="text" maxlength="60" class="input_text_default middle" value="{$list.smtpfrom}"/>
                    </div>
                    <div class="fl">端口：</div>
                    <div class="fr">
                        <input name="smtpport[]" id="smtpport" type="text" maxlength="60" class="input_text_default middle" value="{$list.smtpport}"/>
                        <label class="no-fl-note">默认：25</label>
                    </div>
                    <div class="clear"></div>
                </div>
            </volist>
            <div id="html"></div>
        </div>
        <div class="form_main width150">
            <div class="fl"></div>
            <div class="fr">
                <input name="save" type="submit" class="admin_submit"    value="保存修改"/>
                <input type="button" name="add_form" id="add_form" value="继续添加" class="admin_submit" />
            </div>
            <div class="clear"></div>
        </div>
    </div>
    <div id="aliyun-block" class="form_main width150" style="display:none;">
        <div class="fl">Access Key：</div>
        <div class="fr">
            <input name="aliyun_accessKey" id="aliyun_accessKey" type="text" class="input_text_default middle" value="{$info.aliyun_accessKey}"/>
            <label class="no-fl-note">阿里云Access Key ID</label>
        </div>
        <div class="fl">Access Secret：</div>
        <div class="fr">
            <input name="aliyun_accessSecret" id="aliyun_accessSecret" type="password" class="input_text_default middle" value="{$info.aliyun_accessSecret}"/>
            <label class="no-fl-note">阿里云Access Key Secret</label>
        </div>
        <div class="fl">发信地址：</div>
        <div class="fr">
            <input name="aliyun_account" id="aliyun_account" type="text" class="input_text_default middle" value="{$info.aliyun_account}"/>
            <label class="no-fl-note">管理控制台中配置的发信地址</label>
        </div>
        <div class="fl">标签：</div>
        <div class="fr">
            <input name="aliyun_tag" id="aliyun_tag" type="text" class="input_text_default middle" value="{$info.aliyun_tag}"/>
            <label class="no-fl-note">控制台创建的标签</label>
        </div>
        <div class="fl"></div>
        <div class="fr">
            <input name="save" type="submit" class="admin_submit"    value="保存修改"/>
        </div>
        <div class="clear"></div>
</div>
</form>
</div>
<include file="public:footer" />
<script id="J_email" type="text/html">
<div class="html_tpl form_main width150">
    <div class="fl">SMTP服务器地址：</div>
    <div class="fr">
        <input name="smtpservers[]" id="smtpservers" type="text" maxlength="30" class="input_text_default middle" value=""/>
        <label class="no-fl-note">如：smtp.qq.com</label>
        <span style="color:#0066CC; cursor:pointer" class="delsmtp">X 删除此账户</span>
    </div>
    <div class="fl">SMTP服务帐户名：</div>
    <div class="fr">
        <input name="smtpusername[]" id="smtpusername" type="text" maxlength="100" class="input_text_default middle" value=""/>
    </div>
    <div class="fl">SMTP服务密码：</div>
    <div class="fr">
        <input name="smtppassword[]" id="smtppassword" type="password" maxlength="40" class="input_text_default middle" value=""/>
    </div>
    <div class="fl">发信人邮件地址：</div>
    <div class="fr">
        <input name="smtpfrom[]" id="site_title" type="text" maxlength="60" class="input_text_default middle" value=""/>
    </div>
    <div class="fl">端口：</div>
    <div class="fr">
        <input name="smtpport[]" id="smtpport" type="text" maxlength="60" class="input_text_default middle" value=""/>
        <label class="no-fl-note">默认：25</label>
    </div>
    <div class="clear"></div>
</div>
</script>
<script type="text/javascript">
$(document).ready(function()
{
    setsendmailshow();
    $("#methodsel .radio").click(function(event) {
        var stlval=$(this).attr('data');
        if (stlval=="1") {
            $("#method_sendmail,#add_form").show();
            $("#add_form").show();
        } else {
            $("#method_sendmail,#add_form").hide();
        }
    })
    function setsendmailshow() {
        var stlval=$("#methodsel .select").attr('data');
        if (stlval=="1") {
            $("#method_sendmail,#add_form").show();
            $("#add_form").show();
        } else {
            $("#method_sendmail,#add_form").hide();
        }
    }
    $("#add_form").click(function() {
        $("#html").append($("#J_email").html());
    })

    // 删除账号
    $('.delsmtp').live('click', function() {
        var htNum = $('.html_tpl').length;

        if (htNum==1) {
            alert('至少留一个SMTP账户！');
        } else {
            $(this).closest('.html_tpl').empty();
        }
    });
    // 初始化接口类型
    if($('.api_type').val()=='normal'){
        $('#normal-block').show();
        $('#aliyun-block').hide();
    } else {
        $('#normal-block').hide();
        $('#aliyun-block').show();
    }
    // 接口类型切换
    $('.J_api_type').click(function(){
        var type = $(this).attr('data');
        if(type=='normal'){
            $('#normal-block').show();
            $('#aliyun-block').hide();
            $('.method_first').attr('checked',true);
            $('#method_sendmail').show();
        } else {
            $('#normal-block').hide();
            $('#aliyun-block').show();
        }
    })
});
</script>
</body>
</html>